package net.oschina.app.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import net.oschina.app.Myapp;
import net.oschina.app.R;
import net.oschina.app.bean.Blog;
import net.oschina.app.bean.News;
import net.oschina.app.hjpbean.GeneralBlogDetailBean;
import net.oschina.app.hjpbean.GeneralNewsDetailBean;

import java.util.List;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Admin on 2017/7/16.
 */

public class BoKeActivity extends AppCompatActivity{

    private WebView webView;

    private List<Blog> newsLists;
    @BindView(R.id.zixun_back)
    ImageView zixunBack;
    @BindView(R.id.zixunfengexian)
    TextView zixunfengexian;
    @BindView(R.id.zixun_shuaxin)
    ImageView zixunShuaxin;
    private TextView titletv;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        init();


    }

    private void init() {


        setContentView(R.layout.zixun_activity);

        titletv = (TextView) findViewById(R.id.zixunxiangqing_title);

        getshuju();

//        zixunWv.loadUrl("http://www.oschina.net/action/api/news_detail?id=64198");

//        zixunWv.setWebViewClient(new ZiXunWebViewClient());
    }

    public void getshuju() {

        Intent intent=getIntent();

        String title=intent.getStringExtra("title");

        int a=intent.getIntExtra("id",470948);

        titletv.setText(title);

        Call<GeneralBlogDetailBean> info = Myapp.shopService.getboke(a);

        info.enqueue(new Callback<GeneralBlogDetailBean>() {

            @Override
            public void onResponse(Call<GeneralBlogDetailBean> call, Response<GeneralBlogDetailBean> response) {

//                Log.d("baima", response.body().getNews().getUrl());

                webView = (WebView) findViewById(R.id.zixun_wv);

                webView.loadDataWithBaseURL(null, response.body().getBlog().getBody(), "text/html", "utf-8", null);

//                webView.loadUrl(response.body().getNews().getUrl());


            }


            @Override
            public void onFailure(Call<GeneralBlogDetailBean> call, Throwable t) {

                t.printStackTrace();

            }
        });

    }


    public void zixun_back(View view) {

        finish();

    }

    public void zixun_shuaxin(View view) {

        Toast.makeText(getApplicationContext(), "刷你妹的新！", Toast.LENGTH_SHORT).show();

    }


}
